;;;; Rogue Skirmish copyright 2010 Adam White (theroguemonkey@gmail.com)
;;;; Licensed under GNU General Public Licence v2 or later - refer COPYING

(in-package :skirmish)

(defvar *player-ids* 0)

(defun next-player-id ()
  (incf *player-ids*))

(defclass player (warlord)
  ((player-id :initform 0
    :reader player-id)
   (callback :initform nil
    :accessor player-callback)))


(defun playerp (actor)
  (typep actor 'player))

#||
(defmethod initialize-instance :after ((player player) &key)
  (setf (slot-value player 'player-id) (next-player-id)))



(defmethod act ((player player))
  (let* ((handle (mksymb (list "PLAYER-" (player-id player))))
	 (player-callbacks (make-main-cb player handle)))
    (push-callback handle (first player-callbacks))
    (setf (player-callback player) (second player-callbacks))
    (pop-idle :act)
    0))





(defun make-main-cb (player id)
  (labels ((main-player-input (type &key x y button sym mod &allow-other-keys)
	     (declare (ignorable x y button sym mod))
	     (when (find type '(:key-up :button-up))
	       (return-from main-player-input nil))
	     (cond
	       ((key->direction sym) (move* player (key->direction sym))))))
    
    (let ((callbacks (list #'main-player-input)))       
      (list #'(lambda (&rest args)
		(bwhen result (apply (car callbacks) args)
		       (pop-callback id)
		       (push-idle :act #'act-next)
		       (incf (@next-action player) result)))
	    #'(lambda (command &optional func)
		(case command
		  (:push (push func callbacks))
		  (:pop (pop callbacks))))))))












||#